r*****t 发帖数: 7278 | 1 Black-Scholes formula
和
binomial lattice method
再来玩option
我自己正在结合自己的操作经验 + 历史数据蒙特卡洛分析 + binomial lattice
method
生成一个超级option交易机器,貌似比较有帮助的说。 | x*******i 发帖数: 1791 | 2 我觉得这玩艺有点用烂了。
我正在搞一个新算法。貌似可以赚大钱。
最近没空,过一阵实现一下。 | s******n 发帖数: 6806 | 3 pro每天都在算,世界上计算次数最多的公式。
散户有用没用不清楚。
【在 r*****t 的大作中提到】 : Black-Scholes formula : 和 : binomial lattice method : 再来玩option : 我自己正在结合自己的操作经验 + 历史数据蒙特卡洛分析 + binomial lattice : method : 生成一个超级option交易机器,貌似比较有帮助的说。
| r*****t 发帖数: 7278 | 4 using System;
namespace QFramework
{
///
/// Represents a Cox-Ross-Rubenstein binomial tree option pricing
calculator. May be used for pricing European or American options
///
public class BinomialTree
{
#region "Private Members"
private double assetPrice = 0.0;
private double strike = 0.0;
private double timeStep = 0.0;
private double volatility = 0.0;
private EPutCall putCall = EPutCall.Call;
private double riskFreeRate = 0.0;
private int steps = 0;
#endregion
#region "Properties'
public double AssetPrice
{
get { return assetPrice;}
set { assetPrice = value; }
}
public double Strike
{
get { return strike; }
set { strike = value; }
}
public double TimeStep
{
get { return timeStep; }
set { timeStep = value; }
}
public double Volatility
{
get { return volatility; }
set { volatility = value; }
}
public EPutCall PutCall
{
get { return putCall; }
set{ putCall = value; }
}
public double RiskFreeRate
{
get { return riskFreeRate; }
set { riskFreeRate = value; }
}
public int Steps
{
get { return steps; }
set { steps = value; }
}
#endregion
#region "Constructors"
///
/// Empty constructor. All properties may be set.
///
public BinomialTree()
{
}
///
/// Constructor that takes all parameters used for calculatin option
value using binomial tree
///
///
///
///
///
///
///
///
///
public BinomialTree(
double assetPriceParam,
double strikeParam,
double timeStepParam,
double volatilityParam,
double riskFreeRateParam,
EPutCall putCallParam,
int stepsParam)
{
assetPrice = assetPriceParam;
strike = strikeParam;
volatility = volatilityParam;
timeStep = timeStepParam;
riskFreeRate = riskFreeRateParam;
putCall = putCallParam;
steps = stepsParam;
}
#endregion
#region "Binomial Tree"
///
/// Part of the binomial node value equation, represents the
binomial coefficient
///
///
///
///
private double BinomialCoefficient(int m, int n)
{
return Factorial(n) / (Factorial(m) * Factorial(n - m));
}
///
/// Calculates the value of an individual node in the binomial tree
///
///
///
///
///
private double BinomialNodeValue(int m, int n, double p)
{
return BinomialCoefficient(m, n) * Math.Pow(p, (double)m) * Math
.Pow(1.0 - p, (double)(n - m));
}
///
/// Returns the present value of the option
///
///
public double OptionValue()
{
double totalValue = 0.0;
double u = OptionUp(timeStep, volatility, steps);
double d = OptionDown(timeStep, volatility, steps);
double p = Probability(timeStep, volatility, steps, riskFreeRate
);
double nodeValue = 0.0;
double payoffValue= 0.0;
for (int j = 0; j <= steps; j++)
{
payoffValue = Payoff(AssetPrice * Math.Pow(u, (double)j) *
Math.Pow(d, (double)(steps - j)), strike, putCall);
nodeValue = BinomialNodeValue(j, steps, p);
totalValue += nodeValue * payoffValue;
}
return PresentValue(totalValue, riskFreeRate, timeStep);
}
#endregion
#region "Probabilities"
private double OptionUp(double t, double s, int n)
{
return Math.Exp(s * Math.Sqrt(t / n));
}
private double OptionDown(double t, double s, int n)
{
return Math.Exp(-s * Math.Sqrt(t / n));
}
private double Probability(double t, double s, int n, double r)
{
double d1 = FutureValue(1.0, r, t / n);
double d2 = OptionUp(t, s, n);
double d3 = OptionDown(t, s, n);
return (d1 - d3) / (d2 - d3);
}
#endregion
#region "Payoffs"
private double Payoff(double S, double X, EPutCall PutCall)
{
switch (PutCall)
{
case EPutCall.Call:
return Call(S, X);
case EPutCall.Put:
return Put(S, X);
default:
return 0.0;
}
}
private double Call(double S, double X)
{
return Math.Max(0.0, S - X);
}
private double Put(double S, double X)
{
return Math.Max(0.0, X - S);
}
#endregion
#region "Financial Math Utility Functions"
private double Factorial(int n)
{
double d = 1.0;
for (int j = 1; j <= n; j++)
{
d *= j;
}
return d;
}
private double FutureValue(double P, double r, double n)
{
return P * Math.Pow(1.0 + r, n);
}
private double PresentValue(double F, double r, double n)
{
return F / Math.Exp(r * n);
}
#endregion
}
} | c*****r 发帖数: 8227 | | x*******i 发帖数: 1791 | | x*******i 发帖数: 1791 | 7 迂腐p阿,用专业武器打游击战才是正道。支持楼主。 | z***n 发帖数: 789 | 8 hehe, open source code is free
【在 r*****t 的大作中提到】 : Black-Scholes formula : 和 : binomial lattice method : 再来玩option : 我自己正在结合自己的操作经验 + 历史数据蒙特卡洛分析 + binomial lattice : method : 生成一个超级option交易机器,貌似比较有帮助的说。
| z***n 发帖数: 789 | 9 I'm using QT too, hehe
daniu
【在 r*****t 的大作中提到】 : using System; : namespace QFramework : { : /// : /// Represents a Cox-Ross-Rubenstein binomial tree option pricing : calculator. May be used for pricing European or American options : /// : public class BinomialTree : { : #region "Private Members"
| r******9 发帖数: 2632 | 10 傻得可爱
【在 r*****t 的大作中提到】 : Black-Scholes formula : 和 : binomial lattice method : 再来玩option : 我自己正在结合自己的操作经验 + 历史数据蒙特卡洛分析 + binomial lattice : method : 生成一个超级option交易机器,貌似比较有帮助的说。
|
|