Update:
You could use demux to replay the blockchain then listen to RAM trades to create a mongodb database of each change in the RAM market table.
The only way I've seen is to query the table:
cleos -u https://nodes.get-scatter.com:443 get table eosio eosio rammarket
{
"rows": [{
"supply": "10000000000.0000 RAMCORE",
"base": {
"balance": "11870290976 RAM",
"weight": "0.50000000000000000"
},
"quote": {
"balance": "5789275.3804 EOS",
"weight": "0.50000000000000000"
}
}
],
"more": false
}
Price Formula:
https://developers.eos.io/eosio-cleos/reference#cleos-get-table
https://www.eosrp.io/ is open source as well if you care to look through their code: https://github.com/eosnewyork/erp