Files
QuanTAlib/docs/Comparing_w_TALIB.ipynb
T
2022-11-06 17:20:57 -08:00

149 lines
3.6 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"dotnet_interactive": {
"language": "csharp"
},
"vscode": {
"languageId": "dotnet-interactive.csharp"
}
},
"outputs": [
{
"data": {
"text/html": [
"<div><div></div><div></div><div><strong>Installed Packages</strong><ul><li><span>QuanTAlib, 0.1.10-beta</span></li><li><span>TALib.NETCore, 0.4.4</span></li></ul></div></div>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"#r \"nuget: TALib.NETCore, 0.4.4\" \n",
"#r \"nuget: QuanTAlib, 0.1.10-beta\" \n",
"\n",
"using QuanTAlib;\n",
"using TALib;\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"dotnet_interactive": {
"language": "csharp"
},
"vscode": {
"languageId": "dotnet-interactive.csharp"
}
},
"outputs": [
{
"ename": "Error",
"evalue": "(1,1): error CS0246: The type or namespace name 'YAHOO_Feed' could not be found (are you missing a using directive or an assembly reference?)",
"output_type": "error",
"traceback": [
"(1,1): error CS0246: The type or namespace name 'YAHOO_Feed' could not be found (are you missing a using directive or an assembly reference?)"
]
}
],
"source": [
"YAHOO_Feed aapl = new(2020,\"AAPL\");\n",
"TSeries data = aapl.Close;\n",
"\n",
"data.Count()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"dotnet_interactive": {
"language": "csharp"
},
"vscode": {
"languageId": "dotnet-interactive.csharp"
}
},
"outputs": [],
"source": [
"int period = 10;\n",
"\n",
"//QuanTAlib SMA algorithm\n",
"SMA_Series e = new(data, period, false); \n",
"\n",
"// direct call to SMA from TA-LIB - with stitching NaNs in front\n",
"int outBegIdx, outNbElement;\n",
"double[] output = new double[data.Count];\n",
"double[] nans = new double[period];\n",
"double[] ta_temp = new double[data.Count-period+1];\n",
"Array.Fill(nans, double.NaN);\n",
"Core.Sma(data.v.ToArray(), 0, data.Count-1, ta_temp, out outBegIdx, out outNbElement, period); //TA-LIB SMA method\n",
"nans.CopyTo(output,0);\n",
"ta_temp.CopyTo(output,period-1);\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"dotnet_interactive": {
"language": "csharp"
},
"vscode": {
"languageId": "dotnet-interactive.csharp"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"QuantLib\t TA-LIB\n",
"164.31\t\t 164.31\n",
"166.81\t\t 166.81\n",
"169.20\t\t 169.20\n",
"171.01\t\t 171.01\n",
"172.41\t\t 172.41\n",
"173.45\t\t 173.45\n",
"174.75\t\t 174.75\n",
"175.38\t\t 175.38\n",
"175.54\t\t 175.54\n",
"\n",
"1394\t\t 1394\n"
]
}
],
"source": [
"// comparing the tail of QuanTAlib and TA-LIB\n",
"Console.Write($\"QuanTAlib\\t TA-LIB\\n\");\n",
"for (int i=data.Count-10; i<data.Count-1; i++) \n",
" Console.Write($\"{e[i].v:f2}\\t\\t {output[i]:f2}\\n\");\n",
"\n",
"Console.Write($\"\\n{e.Count()}\\t\\t {output.Length}\\n\");\n"
]
}
],
"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
}