Reputation: 1
I was trying to migrate from python to C++ but it seems that the results are so different. I was using the same library which is talib
in c++
int size = closePrices.size();
std::vector<double> macd(size), signal(size), hist(size);
int outBegIdx, outNbElement;
const int fastPeriod = 12;
const int slowPeriod = 26;
const int signalPeriod = 9;
TA_RetCode retCode = TA_MACD(0, size - 1, closePrices.data(), fastPeriod, slowPeriod, signalPeriod, &outBegIdx, &outNbElement, macd.data(), signal.data(), hist.data());
and in python
import pandas as pd
import talib
import numpy as np
# Load your price data
df = pd.read_csv("EURJPY.csv")
# Calculate MACD
macd, signal, hist = talib.MACD(
df["close"], fastperiod=12, slowperiod=26, signalperiod=9
)
# Save to CSV
pd.DataFrame({"MACD": macd, "Signal": signal, "Histogram": hist}).to_csv(
"macd_results_python.csv"
)
I'm pretty sure they are followed in https://ta-lib.org/ in the docs
Upvotes: -9
Views: 100