Skip to content

Instantly share code, notes, and snippets.

View samsonq's full-sized avatar
🏀
Balling

Samson Qian samsonq

🏀
Balling
View GitHub Profile
Ranked by discretionary assets managed in hedge funds worldwide, in millions, as of June 30, 2018, unless otherwise noted.
Rank Manager Assets Change from 2017
1 Bridgewater Associates $132,756 7.9%
2 AQR Capital Mgmt. $83,700 9.2%
3 Man Group $59,100 11.3%
4 Renaissance Technologies $57,000 17.3%
5 Two Sigma Inv./Two Sigma Advisers $38,800 9.6%
6 Millennium Mgmt. $35,314 2.7%
7 Elliott Management $35,000 7.0%
@samsonq
samsonq / black_litterman.py
Created July 25, 2023 02:48
Black-Litterman Model for Optimal Asset Allocation
import numpy as np
from pypfopt.black_litterman import BlackLittermanModel
from pypfopt.efficient_frontier import EfficientFrontier
from pypfopt import plotting
from openbb_terminal.sdk import openbb
import seaborn as sns
sns.set_theme()
@samsonq
samsonq / arbitrage.py
Created July 22, 2023 03:00 — forked from Valian/arbitrage.py
Short script for finding Binance Triangle arbitrage opportunities - requires python-binance installed
from collections import defaultdict
from operator import itemgetter
from time import time
from binance.client import Client
FEE = 0.0005
PRIMARY = ['ETH', 'USDT', 'BTC', 'BNB']
@samsonq
samsonq / second_largest.py
Last active November 21, 2022 22:24
Second Largest O(n)
def second_largest(n):
first = n[0]
second = n[1]
if second > first:
first, second = second, first
for i in range(2, len(n)):
if n[i] > first:
first, second = n[i], first
if second > first:
first, second = second, first
@samsonq
samsonq / monty_hall.py
Created November 16, 2022 16:27
Monty Hall Problem Simulation
import numpy as np
def monty_hall():
doors = np.array([1, 0, 0])
np.random.shuffle(doors)
initial_choice = np.random.randint(len(doors))
goat_door = 0
for i in range(len(doors)):
if i == initial_choice:
@samsonq
samsonq / fibonacci_dp.py
Created October 26, 2022 14:08
Dynamic Programming
def fib_dp(n, memo):
if n in memo:
return memo[n]
else:
fib_n = fib_dp(n-1, memo) + fib_dp(n-2, memo)
memo[n] = fib_n
return fib_n
def fibonacci_dp(n):
@samsonq
samsonq / poison_bottles.py
Created October 26, 2022 13:58
Poison Bottles
def find_poisoned_bottle(bottles):
"""
Find position of the poisonous wine bottle in 1000 bottles, using 10 strips, given that there
is only 1 poisonous bottle of the 1000 bottles.
The logic is to line up all 10 strips and represent them as binary numbers, with each strip in a position for the
binary numbers. Then, each wine bottle is labeled from 1-1000. Since 2^10 is the first power of 2 that is greater than 1000,
10 strips are sufficient and we only need to test once with all 10 strips, and then wait 1 week for the test results to come back.
Then, aligning the strips in the same order as before, there will be a sequence of positive and negative strips. Converting that
sequence from binary (with positive as 1's and negative as 0's) back into decimal form, we will have the index of the poisoned
@samsonq
samsonq / blackjack_simulation.py
Last active June 28, 2022 22:01
Monte Carlo Simulation to Play Card Games (Poker, Blackjack, etc.)
import numpy as np
import random
@samsonq
samsonq / pi_circle_estimate.py
Created April 16, 2022 16:32
Estimating Pi and Area of Circle with Monte Carlo Simulation
import numpy
import math
from matplotlib import pyplot as plt
def pi_monte_carlo(num_simulations, radius=1):
return ...
if __name__ == "__main__":
@samsonq
samsonq / algo.py
Created February 18, 2022 01:57
Algos
import math
def selection_sort(a):
for i in range(len(a)):
curr_min = i
for j in range(i, len(a)):
if a[j] < a[curr_min]:
curr_min = j
if curr_min != i:
a[i], a[curr_min] = a[curr_min], a[i]