mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-23 04:58:08 +00:00
138 lines
21 KiB
Plaintext
138 lines
21 KiB
Plaintext
{
|
|||
|
|
"cells": [
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 1,
|
||
|
|
"metadata": {
|
||
|
|
"dotnet_interactive": {
|
||
|
|
"language": "csharp"
|
||
|
|
},
|
||
|
|
"vscode": {
|
||
|
|
"languageId": "dotnet-interactive.csharp"
|
||
|
|
}
|
||
|
|
},
|
||
|
|
"outputs": [
|
||
|
|
{
|
||
|
|
"data": {
|
||
|
|
"text/html": [
|
||
|
|
"<div><div></div><div></div><div></div></div>"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
"metadata": {},
|
||
|
|
"output_type": "display_data"
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"data": {
|
||
|
|
"text/plain": [
|
||
|
|
"Loading extensions from `C:\\Users\\miha\\.nuget\\packages\\plotly.net.interactive\\3.0.2\\interactive-extensions\\dotnet\\Plotly.NET.Interactive.dll`"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
"metadata": {},
|
||
|
|
"output_type": "display_data"
|
||
|
|
}
|
||
|
|
],
|
||
|
|
"source": [
|
||
|
|
"//#r \"nuget: QuanTAlib;\"\n",
|
||
|
|
"\n",
|
||
|
|
"#r \"nuget: Plotly.NET;\"\n",
|
||
|
|
"#r \"nuget: Plotly.NET.Interactive;\"\n",
|
||
|
|
"#r \"..\\Source\\bin\\Debug\\net6.0\\QuanTAlib.dll\"\n",
|
||
|
|
"\n",
|
||
|
|
"using QuanTAlib;\n",
|
||
|
|
"using Plotly.NET;\n",
|
||
|
|
"using Plotly.NET.LayoutObjects;"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 10,
|
||
|
|
"metadata": {
|
||
|
|
"dotnet_interactive": {
|
||
|
|
"language": "csharp"
|
||
|
|
},
|
||
|
|
"vscode": {
|
||
|
|
"languageId": "dotnet-interactive.csharp"
|
||
|
|
}
|
||
|
|
},
|
||
|
|
"outputs": [
|
||
|
|
{
|
||
|
|
"data": {
|
||
|
|
"text/html": [
|
||
|
|
"\n",
|
||
|
|
"<div>\n",
|
||
|
|
" <div id=\"962c4ba9-2a84-42ad-98c3-703f45d5e121\"><!-- Plotly chart will be drawn inside this DIV --></div>\r\n",
|
||
|
|
"<script type=\"text/javascript\">\r\n",
|
||
|
|
"\r\n",
|
||
|
|
" var renderPlotly_962c4ba92a8442ad98c3703f45d5e121 = function() {\r\n",
|
||
|
|
" var fsharpPlotlyRequire = requirejs.config({context:'fsharp-plotly',paths:{plotly:'https://cdn.plot.ly/plotly-2.6.3.min'}}) || require;\r\n",
|
||
|
|
" fsharpPlotlyRequire(['plotly'], function(Plotly) {\r\n",
|
||
|
|
"\r\n",
|
||
|
|
" var data = [{\"type\":\"scatter\",\"name\":\"TSeries\",\"mode\":\"lines\",\"x\":[\"2022-10-02T00:00:00-07:00\",\"2022-10-03T00:00:00-07:00\",\"2022-10-04T00:00:00-07:00\",\"2022-10-05T00:00:00-07:00\",\"2022-10-06T00:00:00-07:00\",\"2022-10-07T00:00:00-07:00\",\"2022-10-08T00:00:00-07:00\",\"2022-10-09T00:00:00-07:00\",\"2022-10-10T00:00:00-07:00\",\"2022-10-11T00:00:00-07:00\",\"2022-10-12T00:00:00-07:00\",\"2022-10-13T00:00:00-07:00\",\"2022-10-14T00:00:00-07:00\",\"2022-10-15T00:00:00-07:00\",\"2022-10-16T00:00:00-07:00\",\"2022-10-17T00:00:00-07:00\",\"2022-10-18T00:00:00-07:00\",\"2022-10-19T00:00:00-07:00\",\"2022-10-20T00:00:00-07:00\",\"2022-10-21T00:00:00-07:00\",\"2022-10-22T00:00:00-07:00\",\"2022-10-23T00:00:00-07:00\",\"2022-10-24T00:00:00-07:00\",\"2022-10-25T00:00:00-07:00\",\"2022-10-26T00:00:00-07:00\",\"2022-10-27T00:00:00-07:00\",\"2022-10-28T00:00:00-07:00\",\"2022-10-29T00:00:00-07:00\",\"2022-10-30T00:00:00-07:00\",\"2022-10-31T00:00:00-07:00\",\"2022-11-01T00:00:00-07:00\",\"2022-11-02T00:00:00-07:00\",\"2022-11-03T00:00:00-07:00\",\"2022-11-04T00:00:00-07:00\",\"2022-11-05T00:00:00-07:00\",\"2022-11-06T00:00:00-07:00\",\"2022-11-07T00:00:00-08:00\",\"2022-11-08T00:00:00-08:00\",\"2022-11-09T00:00:00-08:00\",\"2022-11-10T00:00:00-08:00\",\"2022-11-11T00:00:00-08:00\",\"2022-11-12T00:00:00-08:00\",\"2022-11-13T00:00:00-08:00\",\"2022-11-14T00:00:00-08:00\",\"2022-11-15T00:00:00-08:00\",\"2022-11-16T00:00:00-08:00\",\"2022-11-17T00:00:00-08:00\",\"2022-11-18T00:00:00-08:00\",\"2022-11-19T00:00:00-08:00\",\"2022-11-20T00:00:00-08:00\"],\"y\":[100.32347458435882,101.54156680190876,102.44460177741148,102.68134101395528,102.90703954051875,102.22218974495196,101.43717558102097,101.14339741875722,102.6105272974295,103.65021639595955,103.77244362510633,102.03217071889168,100.95960056905396,101.82716864075812,102.03608780622523,101.89749556240788,102.05027651788346,101.89296662244362,102.71278122024542,103.56689298536428,103.9354438863785,103.24510354729804,102.76477917952552,101.90095530425728,101.47329595293144,102.67539644303456,102.67689188308368,102.07205981055867,101.91579337759124,102.34912306155965,103.80939489667225,105.54575716201366,106.52047349743614,106.82928565900164,107.24070967911489,106.51634155110602,105.58402408515623,105.00786537536857,106.0160312037631,106.96286899929171,106.47676587167781,106.10170572188973,106.96937029511614,107.62634022789082,107.27961111806637,108.41831762658114,107.53735531695195,108.03977481595943,107.54241266929029,107.40686186037536],\"marker\":{},\"line\":{\"color\":\"red\",\"width\":4.0}},{\"type\":\"scatter\",\"name\":\"EMA_SMA\",\"mode\":\"lines\",\"x\":[\"2022-10-02T00:00:00-07:00\",\"2022-10-03T00:00:00-07:00\",\"2022-10-04T00:00:00-07:00\",\"2022-10-05T00:00:00-07:00\",\"2022-10-06T00:00:00-07:00\",\"2022-10-07T00:00:00-07:00\",\"2022-10-08T00:00:00-07:00\",\"2022-10-09T00:00:00-07:00\",\"2022-10-10T00:00:00-07:00\",\"2022-10-11T00:00:00-07:00\",\"2022-10-12T00:00:00-07:00\",\"2022-10-13T00:00:00-07:00\",\"2022-10-14T00:00:00-07:00\",\"2022-10-15T00:00:00-07:00\",\"2022-10-16T00:00:00-07:00\",\"2022-10-17T00:00:00-07:00\",\"2022-10-18T00:00:00-07:00\",\"2022-10-19T00:00:00-07:00\",\"2022-10-20T00:00:00-07:00\",\"2022-10-21T00:00:00-07:00\",\"2022-10-22T00:00:00-07:00\",\"2022-10-23T00:00:00-07:00\",\"2022-10-24T00:00:00-07:00\",\"2022-10-25T00:00:00-07:00\",\"2022-10-26T00:00:00-07:00\",\"2022-10-27T00:00:00-07:00\",\"2022-10-28T00:00:00-07:00\",\"2022-10-29T00:00:00-07:00\",\"2022-10-30T00:00:00-07:00\",\"2022-10-31T00:00:00-07:00\",\"2022-11-01T00:00:00-07:00\",\"2022-11-02T00:00:00-07:00\",\"2022-11-03T00:00:00-07:00\",\"2022-11-04T00:00:00-07:00\",\"2022-11-05T00:00:00-07:00\",\"2022-11-06T00:00:00-07:00\",\"2022-11-07T00:00:00-08:00\",\"2022-11-08T00:00:00-08:00\",\"2022-11-09T00:00:00-08:00\",\"2022-11-10T00:00:00-08:00\",\"2022-11-11T00:00:00-08:00\",\"2022-11-12T00:00:00-08:00\",\"2022-11-13T00:00:00-08:00\",\"2022-11-14T00:00:00-08:00\",\"2022-11-15T00:00:00-08:00\",\"2022-11-16T00:00:00-08:00\",\"2022-11-17T00:00:00-08:00\",\
|
||
|
|
" var layout = {\"width\":1200,\"height\":600,\"template\":{\"layout\":{\"title\":{\"x\":0.05},\"font\":{\"color\":\"rgba(42, 63, 95, 1.0)\"},\"paper_bgcolor\":\"rgba(255, 255, 255, 1.0)\",\"plot_bgcolor\":\"rgba(229, 236, 246, 1.0)\",\"autotypenumbers\":\"strict\",\"colorscale\":{\"diverging\":[[0.0,\"#8e0152\"],[0.1,\"#c51b7d\"],[0.2,\"#de77ae\"],[0.3,\"#f1b6da\"],[0.4,\"#fde0ef\"],[0.5,\"#f7f7f7\"],[0.6,\"#e6f5d0\"],[0.7,\"#b8e186\"],[0.8,\"#7fbc41\"],[0.9,\"#4d9221\"],[1.0,\"#276419\"]],\"sequential\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"sequentialminus\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]},\"hovermode\":\"closest\",\"hoverlabel\":{\"align\":\"left\"},\"coloraxis\":{\"colorbar\":{\"outlinewidth\":0.0,\"ticks\":\"\"}},\"geo\":{\"showland\":true,\"landcolor\":\"rgba(229, 236, 246, 1.0)\",\"showlakes\":true,\"lakecolor\":\"rgba(255, 255, 255, 1.0)\",\"subunitcolor\":\"rgba(255, 255, 255, 1.0)\",\"bgcolor\":\"rgba(255, 255, 255, 1.0)\"},\"mapbox\":{\"style\":\"light\"},\"polar\":{\"bgcolor\":\"rgba(229, 236, 246, 1.0)\",\"radialaxis\":{\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"ticks\":\"\"},\"angularaxis\":{\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"ticks\":\"\"}},\"scene\":{\"xaxis\":{\"ticks\":\"\",\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"gridwidth\":2.0,\"zerolinecolor\":\"rgba(255, 255, 255, 1.0)\",\"backgroundcolor\":\"rgba(229, 236, 246, 1.0)\",\"showbackground\":true},\"yaxis\":{\"ticks\":\"\",\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"gridwidth\":2.0,\"zerolinecolor\":\"rgba(255, 255, 255, 1.0)\",\"backgroundcolor\":\"rgba(229, 236, 246, 1.0)\",\"showbackground\":true},\"zaxis\":{\"ticks\":\"\",\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"gridwidth\":2.0,\"zerolinecolor\":\"rgba(255, 255, 255, 1.0)\",\"backgroundcolor\":\"rgba(229, 236, 246, 1.0)\",\"showbackground\":true}},\"ternary\":{\"aaxis\":{\"ticks\":\"\",\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\"},\"baxis\":{\"ticks\":\"\",\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\"},\"caxis\":{\"ticks\":\"\",\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\"},\"bgcolor\":\"rgba(229, 236, 246, 1.0)\"},\"xaxis\":{\"title\":{\"standoff\":15},\"ticks\":\"\",\"automargin\":true,\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"zerolinecolor\":\"rgba(255, 255, 255, 1.0)\",\"zerolinewidth\":2.0},\"yaxis\":{\"title\":{\"standoff\":15},\"ticks\":\"\",\"automargin\":true,\"linecolor\":\"rgba(255, 255, 255, 1.0)\",\"gridcolor\":\"rgba(255, 255, 255, 1.0)\",\"zerolinecolor\":\"rgba(255, 255, 255, 1.0)\",\"zerolinewidth\":2.0},\"annotationdefaults\":{\"arrowcolor\":\"#2a3f5f\",\"arrowhead\":0,\"arrowwidth\":1},\"shapedefaults\":{\"line\":{\"color\":\"rgba(42, 63, 95, 1.0)\"}},\"colorway\":[\"rgba(99, 110, 250, 1.0)\",\"rgba(239, 85, 59, 1.0)\",\"rgba(0, 204, 150, 1.0)\",\"rgba(171, 99, 250, 1.0)\",\"rgba(255, 161, 90, 1.0)\",\"rgba(25, 211, 243, 1.0)\",\"rgba(255, 102, 146, 1.0)\",\"rgba(182, 232, 128, 1.0)\",\"rgba(255, 151, 255, 1.0)\",\"rgba(254, 203, 82, 1.0)\"]},\"data\":{\"bar\":[{\"marker\":{\"line\":{\"color\":\"rgba(229, 236, 246, 1.0)\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"error_x\":{\"color\":\"rgba(42, 63
|
||
|
|
" var config = {\"responsive\":true};\r\n",
|
||
|
|
" Plotly.newPlot('962c4ba9-2a84-42ad-98c3-703f45d5e121', data, layout, config);\r\n",
|
||
|
|
"});\r\n",
|
||
|
|
" };\r\n",
|
||
|
|
" if ((typeof(requirejs) !== typeof(Function)) || (typeof(requirejs.config) !== typeof(Function))) {\r\n",
|
||
|
|
" var script = document.createElement(\"script\");\r\n",
|
||
|
|
" script.setAttribute(\"src\", \"https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js\");\r\n",
|
||
|
|
" script.onload = function(){\r\n",
|
||
|
|
" renderPlotly_962c4ba92a8442ad98c3703f45d5e121();\r\n",
|
||
|
|
" };\r\n",
|
||
|
|
" document.getElementsByTagName(\"head\")[0].appendChild(script);\r\n",
|
||
|
|
" }\r\n",
|
||
|
|
" else {\r\n",
|
||
|
|
" renderPlotly_962c4ba92a8442ad98c3703f45d5e121();\r\n",
|
||
|
|
" }\r\n",
|
||
|
|
"</script>\r\n",
|
||
|
|
"\n",
|
||
|
|
" \n",
|
||
|
|
"</div> \n"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
"metadata": {},
|
||
|
|
"output_type": "display_data"
|
||
|
|
}
|
||
|
|
],
|
||
|
|
"source": [
|
||
|
|
"int period = 25;\n",
|
||
|
|
"GBM_Feed feed = new(50, Volatility: 1);\n",
|
||
|
|
"TSeries data = feed.OHLC4;\n",
|
||
|
|
"//List<double> raw = new() { 0, 1, 1 ,1 ,1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}; \n",
|
||
|
|
"//TSeries data = new();\n",
|
||
|
|
"//for (int i=0; i<raw.Count; i++) { data.Add((DateTime.Today.AddDays(i-raw.Count)),raw[i]); }\n",
|
||
|
|
"\n",
|
||
|
|
"EMA_Series calc1 = new(data,period);\n",
|
||
|
|
"EMA_Series calc2 = new(data,period, useSMA: false);\n",
|
||
|
|
"var line0 = Chart2D.Chart.Line<DateTime,double,bool>(data.t, data.v, false, data.GetType().Name).WithLineStyle(Width: 4, Color: Color.fromString(\"red\"));\n",
|
||
|
|
"var line1 = Chart2D.Chart.Line<DateTime,double,bool>(calc1.t, calc1.v, false, \"EMA_SMA\").WithLineStyle(Width: 2, Color: Color.fromString(\"purple\"));\n",
|
||
|
|
"var line2 = Chart2D.Chart.Line<DateTime,double,bool>(calc2.t, calc2.v, false, \"True EMA\").WithLineStyle(Width: 2, Color: Color.fromString(\"blue\"));\n",
|
||
|
|
"\n",
|
||
|
|
"var chart = Chart.Combine(new []{line0, line1, line2})\n",
|
||
|
|
" .WithSize(1200,600)\n",
|
||
|
|
" .WithMargin(Margin.init<int, int, int, int, int, bool>(30,10,40,30,1,false))\n",
|
||
|
|
" .WithXAxisRangeSlider(RangeSlider.init(Visible:false));\n",
|
||
|
|
"\n",
|
||
|
|
"chart"
|
||
|
|
]
|
||
|
|
}
|
||
|
|
],
|
||
|
|
"metadata": {
|
||
|
|
"kernelspec": {
|
||
|
|
"display_name": ".NET (C#)",
|
||
|
|
"language": "C#",
|
||
|
|
"name": ".net-csharp"
|
||
|
|
},
|
||
|
|
"language_info": {
|
||
|
|
"file_extension": ".cs",
|
||
|
|
"mimetype": "text/x-csharp",
|
||
|
|
"name": "C#",
|
||
|
|
"pygments_lexer": "csharp",
|
||
|
|
"version": "9.0"
|
||
|
|
},
|
||
|
|
"orig_nbformat": 4
|
||
|
|
},
|
||
|
|
"nbformat": 4,
|
||
|
|
"nbformat_minor": 2
|
||
|
|
}
|