Home

Dollar cost averaging

As an engineer paid in a foreign currency, what is the best strategy to maximize your income? Is it better to exchange when you receive your money on a monthly basis? Or is it better to exchange a little bit every week or every day?

TLDR; The daily exchange provides the best results over time on the assumption that the exchange fees are proportional to the exchanged amount.

First, let's grab the USD/BRL prices from Yahoo Finance. I'll use pandas_datareader and yfinance.

import pandas_datareader.data as pdr
import yfinance as yf

yf.pdr_override()

df = pdr.get_data_yahoo('USDBRL=X')

Let S be your annual salary, n be the number of exchanges and (x1, x2, ... xn) the USD/BRL exchange rate at the n periods. Sn is the exchanged amount at each period. The total exchanged amount is: Sn i=1 n xi = S i=1 n xi n = S x ̅

Let m be another number of exchanges and (y1, y2, ... ym) the USD/BRL exchange rate at the m periods. The frequency yielding the optimal exchanged amount is the one with the highest average: S x ̅ S y ̅ x ̅ y ̅

To determine the best frequency for currency exchange, we'll compare averages from three datasets: daily rates, weekly rates, and monthly rates.

Daily rates
In [1]: df["Close"].mean()
Out[1]: 3.1029914017829077
Weekly rates
In [2]: df["Close"].resample("W").first().mean()
Out[2]: 3.09241014059527
Monthly rates
In [3]: df["Close"].resample("M").first().mean()
Out[3]: 3.087195667895404

Over time, the daily exchange will give you the best result, but it doesn't mean that it is always the case. The weekly exchange yields better results if we only take data starting from 2022.

Daily rates
In [4]: df["Close"]["2022":].mean()
Out[4]: 5.099161933890373
Weekly rates
In [5]: df["Close"]["2022":].resample("W").first().mean()
Out[5]: 5.100240080544118
Monthly rates
In [6]: df["Close"]["2022":].resample("M").first().mean()
Out[6]: 5.095680486588251

But if we start from 2020, then the daily exchange is best again.

Daily rates
In [9]: df["Close"]["2020":].mean()
Out[9]: 5.191872068725996
Weekly rates
In [10]: df["Close"]["2020":].resample("W").first().mean()
Out[10]: 5.186581481363356
Monthly rates
In [11]: df["Close"]["2020":].resample("M").first().mean()
Out[11]: 5.182012155320909

Flat exchange fees

Our calculations assume exchange fees are proportional to the exchanged amount A. However, if there's a set fee F for each exchange, the ideal strategy will be influenced by both F and A. Intuitively, a R$1 fee is trivial if you earn R$1M/month.

Using S and (x1, x2, ... xn) the exchanged amount becomes S x ̅ - n F .

Once again, let's see which exchange frequency yields the most total amount: S x ̅ - n F S y ̅ - m F S ( x ̅ - y ̅ ) ( n - m ) F S n - m x ̅ - y ̅ F

To benefit from daily exchanges in 2022, your yearly salary should be around 32,000 times the flat fee. For weekly exchanges, it should be around 4,500 times the fee.

Salary multiplier for daily over monthly in 2022
In [30]: df2022 = df["Close"]["2022":"2022-12-31"]

In [34]: (len(df2022)-12)/(df2022.mean() - df2022.resample("M").first().mean())
Out[34]: 31746.156236195482
Salary multiplier for weekly over monthly in 2022
In [45]: (52-12)/(df2022.resample("W").first().mean() - df2022.resample("M").first().mean())
Out[45]: 4650.885284075261