finance

ZigZag Indicator Metastock Formula to Python

大兔子大兔子 提交于 2021-02-19 05:32:42
问题 I would like to create a zigzag indicator for stocks in Python. I have this Metastock Formula. I dicided to publish this problem here because I don't know any other foro. I saw 2 stackoverflow posts with something like this but they are wrong. As you can see, the indicator tooks the close prices. Thanks for your help. Python code: from __future__ import division import matplotlib.pyplot as plt import numpy as np def islocalmax(x): """Both neighbors are lower, assumes a centered window of size

Converting XML to Pandas

旧时模样 提交于 2021-02-11 14:21:17
问题 Is there a way to convert an XML file (financial statements from IB API) to Pandas without knowing the exact column headers? The rows should reflect the different dates (there are 4 or more datapoints per column). Would also be great to get balance sheet, income statement and cash flow statement separately. I have tried to use beautiful soup but am getting frustrated because it seems like I need to look for each column header specifically and I don't know how to get the data for each date. Im

how to use correctly if statement postgresql

南笙酒味 提交于 2021-02-11 05:58:39
问题 I'm trying to create a trigger that populates a table everytime X amount of rows are added to other table. The logic would be: 1- check how many rows are in table A based on last date on table B. 2- once there are 1000 rows in table A from the last date on table B, add one row to table B Table A stores ticks from market and table B stores OHLC data (Open, High, Low, Close). Ticks have only 3 columns: date, bid and ask. Open is the first known price, Low is the min price, High is the max price

how to use correctly if statement postgresql

﹥>﹥吖頭↗ 提交于 2021-02-11 05:58:35
问题 I'm trying to create a trigger that populates a table everytime X amount of rows are added to other table. The logic would be: 1- check how many rows are in table A based on last date on table B. 2- once there are 1000 rows in table A from the last date on table B, add one row to table B Table A stores ticks from market and table B stores OHLC data (Open, High, Low, Close). Ticks have only 3 columns: date, bid and ask. Open is the first known price, Low is the min price, High is the max price

Mouse Hover in matplotlib candlestick for python

纵然是瞬间 提交于 2021-02-08 10:55:39
问题 I have implemented this example: http://matplotlib.sourceforge.net/examples/pylab_examples/finance_demo.html?highlight=candlestick I would like to implement mouse hover features for the candlestick so that I can see the candlestick's open/high/low/close either in a popup or a label in a certain panel. I was following along with: http://matplotlib.sourceforge.net/examples/event_handling/pick_event_demo.html Unfortunately, the function: candlestick(ax, quotes, width=0.6) does not have a picker

Mouse Hover in matplotlib candlestick for python

守給你的承諾、 提交于 2021-02-08 10:55:04
问题 I have implemented this example: http://matplotlib.sourceforge.net/examples/pylab_examples/finance_demo.html?highlight=candlestick I would like to implement mouse hover features for the candlestick so that I can see the candlestick's open/high/low/close either in a popup or a label in a certain panel. I was following along with: http://matplotlib.sourceforge.net/examples/event_handling/pick_event_demo.html Unfortunately, the function: candlestick(ax, quotes, width=0.6) does not have a picker

Efficiently calculating point of control with pandas

馋奶兔 提交于 2021-02-08 10:35:13
问题 My algorithm stepped up from 35 seconds to 15 minutes runtime when implementing this feature over a daily timeframe. The algo retrieves daily history in bulk and iterates over a subset of the dataframe (from t0 to tX where tX is the current row of iteration). It does this to emulate what would happen during the real time operations of the algo. I know there are ways of improving it by utilizing memory between frame calculations but I was wondering if there was a more pandas-ish implementation

S&P 500 List python script crashes

泪湿孤枕 提交于 2021-02-07 11:01:11
问题 So I have been following a youtube tutorial on Python finance and since Yahoo has now closed its doors to the financial market, it has caused a few dwelling problems. I run this code import bs4 as bs import datetime as dt import os import pandas as pd import pandas_datareader.data as web import pickle import requests from pandas_datareader import data as pdr import fix_yahoo_finance as yf def save_sp500_tickers(): resp = requests.get('https://en.wikipedia.org /wiki/List_of_S%26P_500_companies

Groupby id to calculate ratios

二次信任 提交于 2021-01-29 16:11:36
问题 Objective I have this df and take some ratios below. I want to calculate these ratios by each id and datadate and I believe the groupby function is the way to go, however I am not exactly sure. Any help would be super! df id datadate dltt ceq ... pstk icapt dlc sale 1 001004 1975-02-28 3.0 193.0 ... 1.012793 1 0.20 7.367237 2 001004 1975-05-31 4.0 197.0 ... 1.249831 1 0.21 8.982741 3 001004 1975-08-31 5.0 174.0 ... 1.142086 2 0.24 8.115609 4 001004 1975-11-30 8.0 974.0 ... 1.400673 3 0.26 9

constrOptim: Minimise a loss function to calibrate option model parameters using the Feller Condition

别来无恙 提交于 2021-01-29 08:13:03
问题 I want to calibrate the Heston SV model (http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.139.3204&rep=rep1&type=pdf) using the function callHestoncf from the package NMOF . For that I need to estimate four structural parameters (vT, rho, k & sigma) using a loss function. The loss function is a weighted sum of squared errors of the form 1/N * sum(w_i * (market_price - model_price)^2) where the weight is 1/market_price. The code is structured as follows: Random sample data from whole