Cursory investigation suggests that it's pretty simple. From TradeRouteData.cpp:
That GetDistanceToGood is in terms of least movement cost to the good (I'm not sure if this gets recalculated as more roads, etc. are built).
sint32 TradeRouteData::GetValue() const
if(m_sourceRouteType != ROUTE_TYPE_RESOURCE)
double baseValue = g_theWorld->GetGoodValue(m_sourceResource);
double distance = double(m_destinationCity->GetCityData()->GetDistanceToGood(m_sourceResource));
return sint32(baseValue * distance);
I guess this may be processed further (taking into account city populations, or something like that). I suggest you investigate - I guess you'd either want to look for calls to the above function or else work the other way from wherever the values get used (e.g. the trade screen).