Skip to content

Instantly share code, notes, and snippets.

@vishalbelsare
vishalbelsare / configure_cuda_p70.md
Created February 14, 2023 23:09 — forked from alexlee-gk/configure_cuda_p70.md
Use integrated graphics for display and NVIDIA GPU for CUDA on Ubuntu 14.04

This was tested on a ThinkPad P70 laptop with an Intel integrated graphics and an NVIDIA GPU:

lspci | egrep 'VGA|3D'
00:02.0 VGA compatible controller: Intel Corporation Device 191b (rev 06)
01:00.0 VGA compatible controller: NVIDIA Corporation GM204GLM [Quadro M3000M] (rev a1)

A reason to use the integrated graphics for display is if installing the NVIDIA drivers causes the display to stop working properly. In my case, Ubuntu would get stuck in a login loop after installing the NVIDIA drivers. This happened regardless if I installed the drivers from the "Additional Drivers" tab in "System Settings" or the ppa:graphics-drivers/ppa in the command-line.

# Backtest of ETF Replay Ranking Algorithm
# clear the workspace
rm(list=ls())
# step-by-step example of ETF Replay Ranking Algorithm
##### etfReplayRank Function #####
# we can use the same step-by-step approach outlined above to write a function
# to rank instruments based on ETF Replay
@vishalbelsare
vishalbelsare / etfReplayRank.R
Created September 19, 2022 22:56 — forked from rbresearch/etfReplayRank.R
implementation of ranking algorithm similar to ETF Replay
# Ranking Algorithm for ETF Replay
# Rank based on 3 factors
# 1. ReturnA (ret1)
# 2. ReturnB (ret2)
# 3. Volatility (vol)
# Returns are ranked from high to low
# Volatility is ranked from low to high
@vishalbelsare
vishalbelsare / orthogonalization.py
Created September 8, 2022 22:34 — forked from nicklatin/orthogonalization.py
Klein and Chow (2013) propose an optimal simultaneous orthogonal transformation of factors, following the so-called symmetric procedure of Schweinler and Wigner (1970) and Löwdin (1970): https://www.sciencedirect.com/science/article/abs/pii/S1062976913000185. The data transformation allows the identification of the underlying uncorrelated compon…
# orthogonalization of correlated factors in a multifactor model
def orthogonalize_factors(factors_df, output_format='df'):
"""
As described by Klein and Chow (2013) in Orthogonalized Factors and Systematic Risk Decompositions:
https://www.sciencedirect.com/science/article/abs/pii/S1062976913000185
They propose an optimal simultaneous orthogonal transformation of factors, following the so-called symmetric procedure
of Schweinler and Wigner (1970) and Löwdin (1970). The data transformation allows the identification of the underlying uncorrelated
components of common factors without changing their correlation with the original factors. It also facilitates the systematic risk
decomposition by disentangling the coefficient of determination (R²) based on factors' volatilities, which makes it easier to distinguish
@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.
@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 / 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.
# 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 / 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": [
{
@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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.