紀錄並推薦程式交易的好網站
Ray's Blog
請賜予寧靜的心去接受無法改變的事, 請賜予勇氣去改變可以改變的事, 並請賜予智慧去分辨這兩者
就是愛現 ~ 程式交易
Hold住未來歷史重演的考古題與紀律執行
兩個推薦網站的內容包含了非常多程式交易的測試、交易的邏輯、指標設計、語法介紹及交易經驗,尤其是非常多的圖表說明使得文章容易理解,對於期貨交易的朋友來說,是很好的參考網站,L 自己也從中參考學習了許多。
對於好網站應該多鼓勵支持,希望站長們都能保持足夠的熱情持續分享,共同進步和獲利。
Function civ(S, K, T, R, Target)
high = 1
low = 0
Do While (high - low) > 0.00001
If PriceC(S, K, T, R, (high + low) / 2) > Target Then
high = (high + low) / 2
Else
low = (high + low) / 2
End If
Loop
civ = (high + low) / 2
End Function
Function piv(S, K, T, R, Target)
high = 1
low = 0
Do While (high - low) > 0.00001
If PriceP(S, K, T, R, (high + low) / 2) > Target Then
high = (high + low) / 2
Else
low = (high + low) / 2
End If
Loop
piv = (high + low) / 2
End Function
Function d1(S, K, T, R, V)
d1 = (Log(S / K) + (R * T) + (V ^ 2 * T / 2)) / (V * Sqr(T))
End Function
Function d2(S, K, T, R, V)
d2 = d1(S, K, T, R, V) - V * Sqr(T)
End Function
Function PriceC(S, K, T, R, V)
PriceC = S * Application.NormSDist(d1(S, K, T, R, V)) - K * Exp(-(R * T)) * Application.NormSDist(d2(S, K, T, R, V))
End Function
Function PriceP(S, K, T, R, V)
PriceP = K * Exp(-R * T) * Application.NormSDist(-d2(S, K, T, R, V)) - S * Application.NormSDist(-d1(S, K, T, R, V))
End Function
class Option
{
public double CallPrice;
public double PutPrice;
public void Price(double S, double K, double R, double T, double V)
{
double a = Math.Log(S / K);
double b_call = (R + 0.5 * Math.Pow(V, 2)) * T;
double b_put = (R - 0.5 * Math.Pow(V, 2)) * T;
double c = V * Math.Sqrt(T);
double d1 = (a + b_call) / c;
double d2 = (a + b_put) / c;
CallPrice = S * ND(d1) - K * Math.Exp(-R * T) * ND(d2);
PutPrice = K * Math.Exp(-R * T) * ND(-d2) - S * ND(-d1);
}
public double PriceC(double S, double K, double R, double T, double V)
{
double a = Math.Log(S / K);
double b_call = (R + 0.5 * Math.Pow(V, 2)) * T;
double b_put = (R - 0.5 * Math.Pow(V, 2)) * T;
double c = V * Math.Sqrt(T);
double d1 = (a + b_call) / c;
double d2 = (a + b_put) / c;
CallPrice = S * ND(d1) - K * Math.Exp(-R * T) * ND(d2);
return CallPrice;
}
public double PriceP(double S, double K, double R, double T, double V)
{
double a = Math.Log(S / K);
double b_call = (R + 0.5 * Math.Pow(V, 2)) * T;
double b_put = (R - 0.5 * Math.Pow(V, 2)) * T;
double c = V * Math.Sqrt(T);
double d1 = (a + b_call) / c;
double d2 = (a + b_put) / c;
PutPrice = K * Math.Exp(-R * T) * ND(-d2) - S * ND(-d1);
return PutPrice;
}
public double ND(double d)
{
double L = 0.0;
double K = 0.0;
double dD = 0.0;
const double a1 = 0.31938153;
const double a2 = -0.356563782;
const double a3 = 1.781477937;
const double a4 = -1.821255978;
const double a5 = 1.330274429;
L = Math.Abs(d);
K = 1.0 / (1.0 + 0.2316419 * L);
dD = 1.0 - 1.0 / Math.Sqrt(2 * Convert.ToDouble(Math.PI)) * Math.Exp(-L * L / 2.0) * (a1 * K + a2 * K * K + a3 * Math.Pow(K, 3.0) + a4 * Math.Pow(K, 4.0) + a5 * Math.Pow(K, 5.0));
if (d < 0) {return 1.0 - dD;}else{return dD;}
}
public double d1(double S, double K, double R, double T, double V)
{
double a = Math.Log(S / K);
double b_call = (R + 0.5 * Math.Pow(V, 2)) * T;
double c = V * Math.Sqrt(T);
double d1 = (a + b_call) / c;
return d1;
}
public double civ(double S, double K, double R, double T, double Target)
{
double high = 1;
double low = 0;
while ((high - low) > 0.00001)
{
if (PriceC(S, K, R, T, (high + low) / 2) > Target) { high = (high + low) / 2; }
else {low = (high + low) / 2;}
}
double civ = (high + low) / 2;
return civ;
}
public double piv(double S, double K, double R, double T, double Target)
{
double high = 1;
double low = 0;
while ((high - low) > 0.00001)
{
if (PriceP(S, K, R, T, (high + low) / 2) > Target)
{high = (high + low) / 2;} else {low = (high + low) / 2;}
}
double piv = (high + low) / 2;
return piv;
}
}