紀錄並推薦程式交易的好網站
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;
}
}
If DM=30 and DW=4 then STWSD =1;
If DM=30 and DW=3 then STWSD =1;
If DM=30 and DW=2 then STWSD =1;
If DM=30 and DW=1 then STWSD =1;
if DM=29 and DW=4 then STWSD =1;
if DM=28 and DW=5 then STWSD =1;
if DM=28 and DW=4 then STWSD =1;
If DM=29 and DW=4 then STWSD =1;
If DM=29 and DW=3 then STWSD =1;
If DM=29 and DW=2 then STWSD =1;
If DM=29 and DW=1 then STWSD =1;
if DM=28 and DW=4 then STWSD =1;
if DM=27 and DW=5 then STWSD =1;
if DM=27 and DW=4 then STWSD =1;
If DM=27 and DW=4 then STWSD =1;
If DM=27 and DW=3 then STWSD =1;
If DM=27 and DW=2 then STWSD =1;
If DM=27 and DW=1 then STWSD =1;
if DM=26 and DW=4 then STWSD =1;
if DM=25 and DW=5 then STWSD =1;
if DM=25 and DW=4 then STWSD =1;
然而透過這樣的觀察就真的可以交易致富? 從 快思慢想 一書中所提及的因果關係來看,我們是型態的尋找者,合理世界的信仰者,因為系統一不善於懷疑,並有自動搜尋因果與建立故事的能力,將看到的現象合理化,除非立刻被否定,否則我們會認為訊息是真的。
最後透過以上的小案例與心理學的分析,J期望讀者能多留意自己是否也在不知不覺中受到的因果關係與小數法則的影響,建議透過程式交易的輔助,產生盡量多的交易次數,減少直覺誤把隨機事件判斷為系統化的結果,並試著去相信回測的大數法則,其驗證將優於我們眼睛所看到的市場規律與近期小量的表現,讓取樣運氣與錯誤的因果連結降低,達成長期穩定的交易。