Skip to content

Instantly share code, notes, and snippets.

import numpy as np
import pandas as pd
from datetime import datetime
from fastparquet import write
def compute_vwap(df):
q = df['foreignNotional']
p = df['price']
@vishalbelsare
vishalbelsare / frac-diff_sk
Created March 16, 2021 20:25 — forked from skuttruf/frac-diff_sk
Python code for fractional differencing of pandas time series
"""
Python code for fractional differencing of pandas time series
illustrating the concepts of the article "Preserving Memory in Stationary Time Series"
by Simon Kuttruf
While this code is dedicated to the public domain for use without permission, the author disclaims any liability in connection with the use of this code.
"""
import numpy as np
import pandas as pd
def dc(ohlcv, thresh=0.005):
upturn_event = True
p_h = p_l = ohlcv['close'][0]
dc_ranges = defaultdict(list)
tuples = tuple(ohlcv.itertuples())
# here we find the timedelta between the timeseries index, 1 and 0, so 1 day for daily data
step = tuples[1].Index - tuples[0].Index
# loop over tuples of ohlcv and time as Index,
@vishalbelsare
vishalbelsare / morningstar.com API.md
Created December 11, 2020 09:35 — forked from jimmysitu/morningstar.com API.md
morningstar.com API

morningstar.com API

  • Get key ratio, return csv format file
http://financials.morningstar.com/ajax/exportKR2CSV.html?t=<market>:<stock>

Market

  • XHKG: Hong Kong Stock Exchange
  • XASE: American Stock Exchange
  • XNAS: Nasdaq Stock Exchange >* XNYS: New York Stock Exchange
@vishalbelsare
vishalbelsare / stock_price_autoencoding.ipynb
Created May 14, 2020 20:43 — forked from GerardBCN/stock_price_autoencoding.ipynb
Stock market Bitcoin data compression with autoencoders
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@vishalbelsare
vishalbelsare / almgren_chriss.py
Created January 22, 2020 11:27 — forked from flipdazed/almgren_chriss.py
Linear Almgren-Chriss python model
import numba as nb
import numpy as np
def impact_perm(nu, gamma, beta):
"""Returns the permenant dollar price impact per unit time
In paper as :math:`g(\nu)`
Args:
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@vishalbelsare
vishalbelsare / my-python-config.el
Created September 22, 2019 13:21
Elpy and conda for a complete python config with Anaconda Python Distribution (handles virtualenvs including python process)
;; See my explanation of this config here: https://github.com/jorgenschaefer/elpy/issues/1087
(provide 'my-python-config)
(require 'python)
;;; NOTE: PATH environment var must have your path to Anaconda
;;; environment, e.g., ~/anaconda/bin, as the last thing for
;;; everything else below to work.
;;; [[file:~/Encrypted/org-mode-repo/OrgModeFiles/howto-python.org]]
;;; explains how to work with Anaconda virtual envs and Emacs.
@vishalbelsare
vishalbelsare / factor_analysis.py
Created September 22, 2019 13:19 — forked from analyticd/factor_analysis.py
simple factor analysis using python/pandas
# basic factor analysis
# http://blog.alphaarchitect.com/2015/05/28/basic-factor-analysis-simple-tools-to-understand-what-drives-performance/
import pandas as pd
import pandas.io.data as web
import datetime, re, copy
import numpy as np
import statsmodels.formula.api as sm
start = datetime.date(2000,1,1)
@vishalbelsare
vishalbelsare / factor_analysis.py
Created September 22, 2019 13:12 — forked from schalekamp/factor_analysis.py
simple factor analysis using python/pandas
# basic factor analysis
# http://blog.alphaarchitect.com/2015/05/28/basic-factor-analysis-simple-tools-to-understand-what-drives-performance/
import pandas as pd
import pandas.io.data as web
import datetime, re, copy
import numpy as np
import statsmodels.formula.api as sm
start = datetime.date(2000,1,1)