Skip to content

Instantly share code, notes, and snippets.

View yuyasugano's full-sized avatar
🏠
Working from home

Yuya Sugano yuyasugano

🏠
Working from home
View GitHub Profile
@yuyasugano
yuyasugano / sharperatio_apple.py
Created September 16, 2020 11:50
Pandas sharpe ratio calculation for Apple Inc
# compute sharpe ratio using Pandas rolling and std methods, the trading days is set to 252 days
TRADING_DAYS = 252
returns = np.log(df['Close']/df['Close'].shift(1))
returns.fillna(0, inplace=True)
volatility = returns.rolling(window=TRADING_DAYS).std()*np.sqrt(TRADING_DAYS)
sharpe_ratio = returns.mean()/volatility
sharpe_ratio.tail()
fig = plt.figure(figsize=(15, 7))
ax3 = fig.add_subplot(1, 1, 1)
@yuyasugano
yuyasugano / FlashExecution.sol
Created July 14, 2020 03:17
aave flash loan example by using OrFeed arb function to perform trianglular arbitrage.
pragma solidity ^0.5.0;
pragma experimental ABIEncoderV2;
import "./aave/FlashLoanReceiverBase.sol";
import "./aave/ILendingPoolAddressesProvider.sol";
import "./aave/ILendingPool.sol";
import "./IKyberNetworkProxy.sol";
import "./IUniswapExchange.sol";
import "./IUniswapFactory.sol";
@yuyasugano
yuyasugano / fetchOHLCV_test.py
Last active October 2, 2025 12:23
ccxt library in Python to fetch OHLCV data test
#!/usr/bin/python
import ccxt
import calendar
from datetime import datetim
binance = ccxt.binance()
now = datetime.utcnow()
unixtime = calendar.timegm(now.utctimetuple())
since = (unixtime - 60*60) * 1000 # UTC timestamp in milliseconds
@yuyasugano
yuyasugano / get_node_id.sh
Created May 13, 2021 03:07
get your node ID in Avalanche
curl -X POST --data '{
"jsonrpc": "2.0",
"method": "info.getNodeID",
"params":{},
"id": 1
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/info
{"jsonrpc":"2.0","result":{"nodeID":"NodeID-EggGmnQFaTffeRNG1Kzs9dXJzFGdxac3D"},"id":1}
@yuyasugano
yuyasugano / flashbots_goerli.js
Created May 27, 2021 01:18
flashbots sample
const ethers = require('ethers');
const { FlashbotsBundleProvider} = require('@flashbots/ethers-provider-bundle')
// Standard json rpc provider directly from ethers.js. For example you can use Infura, Alchemy, or your own node.
// This sample uses one of the default provider goerli
const provider = new ethers.getDefaultProvider("goerli");
// `authSigner` is an Ethereum private key that does NOT store funds and is NOT your bot's primary key.
// This is an identifying key for signing payloads to establish reputation and whitelisting
const authSigner = new ethers.Wallet(
@yuyasugano
yuyasugano / ema_backtesting.py
Created August 1, 2020 09:13
backtesting.py ema strategy
from backtesting import Strategy
from backtesting.lib import crossover
def EMA_Backtesting(values, n):
"""
Return exponential moving average of `values`, at
each step taking into account `n` previous values.
"""
close = pd.Series(values)
return talib.EMA(close, timeperiod=n)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract MyToken is ERC721, ERC721URIStorage, ERC721Burnable, Ownable {
constructor(address initialOwner)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
contract Marketplace is ReentrancyGuard, Ownable {
using Counters for Counters.Counter;
@yuyasugano
yuyasugano / Flashswap.sol
Created October 3, 2021 06:55
Modified Flashswap.sol for PancakeSwap & ApeSwap
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.6.6 <0.8.0;
import './utils/SafeMath.sol';
import './UniswapV2Library.sol';
import './interfaces/IERC20.sol';
import './interfaces/IUniswapV2Pair.sol';
import './interfaces/IUniswapV2Factory.sol';
import './interfaces/IUniswapV2Router02.sol';
@yuyasugano
yuyasugano / flashswaps.sol
Created April 3, 2021 00:39
Flash Swaps arbitrage
function startArbitrage(
address token0,
address token1,
uint amount0,
uint amount1
) external {
address pairAddress = IUniswapV2Factory(pancakeFactory).getPair(token0, token1);
require(pairAddress != address(0), 'This pool does not exist');
IUniswapV2Pair(pairAddress).swap(