Skip to content

Instantly share code, notes, and snippets.

@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
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 / 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
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 / multi-face.ipynb
Created July 24, 2021 18:38 — forked from yang-zhang/multi-face.ipynb
Multi-task Deep Learning Experiment using fastai Pytorch
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@vishalbelsare
vishalbelsare / ERGM_from_scratch
Last active August 10, 2021 17:47 — forked from dmasad/ERGM_from_scratch
Implementing an ERGM from scratch
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
# lazy data frame
#
# like idata.frame, but exploits lazy evaluation + macro code generation
# instead of active bindings
library(vadr)
lazy.frame <- function(df, enclos=parent.frame(), ...) UseMethod("lazy.frame")
lazy.frame.lazy.frame <- function(df, ...) df
@vishalbelsare
vishalbelsare / bookmarks_from_sql.py
Created September 5, 2021 23:44 — forked from iafisher/bookmarks_from_sql.py
Programmatically access your Firefox bookmarks
"""
A script to automatically export bookmarks from Firefox's SQLite database.
There does not seem to be a programmatic way to get Firefox to export its bookmarks in
the conventional HTML format. However, you can access the bookmark information directly
in Firefox's internal database, which is what this script does.
Always be careful when working with the internal database! If you delete data, you will
likely not be able to recover it.
@vishalbelsare
vishalbelsare / macro_factor_mimicking_portfolios.py
Created September 8, 2022 22:33 — forked from nicklatin/macro_factor_mimicking_portfolios.py
Takes observable macro factors (surprises) as inputs and creates macro factor-mimicking portfolios (MFMPs) as outputs. It uses a novel machine-learning approach, the Principal Components Instrumental Variables FMP Estimator, described by Jurczenko and Teiletche (2020) in Macro Factor-Micking Portfolios: https://papers.ssrn.com/sol3/papers.cfm?ab…
"""
This function takes observable macro factors (surprises) as inputs and creates macro factor mimicking portfolios (MFMPs) as outputs. It uses
a novel machine-learning approach, the Principal Components Instrumental Variables FMP Estimator,
described by Jurczenko and Teiletche (2020) in Macro Factor-Micking Portfolios:
https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3363598
The methodology addresses many of the common problems associated with macro factors and multifactor risk modeling and, as they show,
is superior to other common FMP approaches.
We describe the steps of the PCIV algorithm below, as well as in our Medium post:
For a more detailed explanation, see the link to the paper above.
Note that access to macroeconomic and base assets is required to estimate macro factor-mimicking portfolios. See the macro factors
@vishalbelsare
vishalbelsare / high_low_spread_estimator.py
Created September 8, 2022 22:33 — forked from nicklatin/high_low_spread_estimator.py
Computes the high-low spread estimator, an estimate of bid-offer spreads, a measure of liquidity risk. See Corwin & Schultz (2011) for details: https://papers.ssrn.com/sol3/papers.cfm?abstract_id=1106193
# high-low spread estimator (hlse)
def hlse(ohlc_df, frequency='daily'):
"""
Computes the high-low spread estimator, an estimate of bid-offer spreads, a measure of liquidity risk.
See Corwin & Schultz (2011) for details: https://papers.ssrn.com/sol3/papers.cfm?abstract_id=1106193
Parameters
----------
ohlc_df: DataFrame
DataFrame with DatetimeIndex and Open, High, Low and Close (OHLC) prices from which to compute the high-low spread estimates.