Skip to content

Instantly share code, notes, and snippets.

View flcong's full-sized avatar

Linxiao Francis Cong flcong

View GitHub Profile
@flcong
flcong / fast_split_apply_combine.ipynb
Last active March 26, 2024 02:24
Fast Split-Apply-Combine using Numba
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@flcong
flcong / build_quantlib_vs2019.md
Last active May 11, 2022 07:36
Build QuantLib in Windows using Visual Studio 2019

Build QuantLib on Visual Studio 2019

Introduction

There are excellent tutorials to build QuantLib in Windows using Visual Studio 2017. However, in Visual Studio 2019, there are some updates that slightly changes the building process. I follow the procedure in the link above and explored how to adapt to the changes in Visual Studio 2019. The main issue is that Visual Studio 2019 no longer automatically add user property sheets to all projects. Hence, we have to create a property sheet manually and then add it to all projects.

Download and build boosts

  • Download boosts boost_1_75_0.zip from here and unzip into C:\local\
  • Run C:\local\boost_1_75_0\tools\build\bootstrap.bat to get b2.exe
@flcong
flcong / GlobalVariablesJulia.md
Last active August 30, 2023 05:50
Global Variable in Julia: How to avoid using it?

Global Variable in Julia: How to avoid using it?

Recently, I tried to rewrite a MATLAB program in Julia. The program solves a PDE derived from a continuous-time economic model. I got the same result as the MATLAB program, but it was much slower. Then, I reviewed the Performance Tips of Julia and realized that the problem lied in using global variables. Typically, there are a lot of parameters in an economic model and they are typically directly defined as global variables. Then, for convenience, I wrote several functions to calculate some formulae which use these parameters. Since those functions were frequently called in a long loop, the performance is low.

To guide future programming practice, here I experiment several ways to avoid this problem.

Performance with/without global variables

Before digging into various ways to avoid this problem, let's first check how slow using global variables can be. To compare the computational time of di

@flcong
flcong / pythontips.md
Last active November 26, 2023 20:23
Pandas Tips

Python Tips

Introduction

In this Gist, I will keep updating tips for python that I encounter in data analysis, especially for empirical research in finance.

Pandas

Append a large number of DataFrames

This tip comes from Modern Pandas (Part 4): Performance. When appending a large number of DataFrames read from CSV files, instead of appending one by one as follows:

data = pd.DataFrame([])
for f in files:
@flcong
flcong / PythonFinance.md
Last active December 16, 2022 04:53
Python for Empirical Research in Finance/Economics

Python for Empirical Research in Finance/Economics

Introduction

Although mainstream packages for empirical research in finance/economics are SAS, MATLAB, and Stata, I prefer python. There are not many updated documents and tutorials about python in its application to empirical research in finance/economics. Professor Kevin Sheppard's tutorial for Python in Econometrics is an excellent start, but its lecture notes have not kept pace on the fast growing of python packages. For example, some methods in the lecture notes will be deprecated soon according to the new documentation of pandas, such as DataFrame.ix and Panel. Meanwhile, the documentation of pandas is voluminous and hard for researchers to grab essential information as fast as possible.

Therefore, I would like to create this file to keep a record on important objects, methods, and properties that I frequently encounter in my empirical research. It can be regarded as a cheatsheet for resea