Never price commodities using annotated commodities
This commit is contained in:
parent
4b2b9dc009
commit
8e8c2904f5
6 changed files with 35 additions and 24 deletions
|
|
@ -757,10 +757,10 @@ amount_t::value(const datetime_t& moment,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! point) {
|
|
||||||
if (comm && commodity().referent() == comm->referent())
|
if (comm && commodity().referent() == comm->referent())
|
||||||
return *this;
|
return with_commodity(comm->referent());
|
||||||
|
|
||||||
|
if (! point) {
|
||||||
point = commodity().find_price(comm, moment);
|
point = commodity().find_price(comm, moment);
|
||||||
|
|
||||||
// Whether a price was found or not, check whether we should attempt
|
// Whether a price was found or not, check whether we should attempt
|
||||||
|
|
|
||||||
|
|
@ -544,6 +544,15 @@ public:
|
||||||
*this = 0L;
|
*this = 0L;
|
||||||
commodity_ = &comm;
|
commodity_ = &comm;
|
||||||
}
|
}
|
||||||
|
amount_t with_commodity(const commodity_t& comm) const {
|
||||||
|
if (commodity_ == &comm) {
|
||||||
|
return *this;
|
||||||
|
} else {
|
||||||
|
amount_t tmp(*this);
|
||||||
|
tmp.set_commodity(const_cast<commodity_t&>(comm));
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
void clear_commodity() {
|
void clear_commodity() {
|
||||||
commodity_ = NULL;
|
commodity_ = NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -288,7 +288,7 @@ annotated_commodity_t::find_price(const commodity_t * commodity,
|
||||||
return find_price_from_expr(const_cast<expr_t&>(*details.value_expr),
|
return find_price_from_expr(const_cast<expr_t&>(*details.value_expr),
|
||||||
commodity, when);
|
commodity, when);
|
||||||
|
|
||||||
return commodity_t::find_price(target, moment, oldest);
|
return commodity_t::find_price(target, when, oldest);
|
||||||
}
|
}
|
||||||
|
|
||||||
commodity_t&
|
commodity_t&
|
||||||
|
|
|
||||||
|
|
@ -56,14 +56,14 @@ void commodity_t::add_price(const datetime_t& date, const amount_t& price,
|
||||||
DEBUG("history.find", "Adding price: " << symbol()
|
DEBUG("history.find", "Adding price: " << symbol()
|
||||||
<< " for " << price << " on " << date);
|
<< " for " << price << " on " << date);
|
||||||
|
|
||||||
pool().commodity_price_history.add_price(*this, date, price);
|
pool().commodity_price_history.add_price(referent(), date, price);
|
||||||
|
|
||||||
base->price_map.clear(); // a price was added, invalid the map
|
base->price_map.clear(); // a price was added, invalid the map
|
||||||
}
|
}
|
||||||
|
|
||||||
void commodity_t::remove_price(const datetime_t& date, commodity_t& commodity)
|
void commodity_t::remove_price(const datetime_t& date, commodity_t& commodity)
|
||||||
{
|
{
|
||||||
pool().commodity_price_history.remove_price(*this, commodity, date);
|
pool().commodity_price_history.remove_price(referent(), commodity, date);
|
||||||
|
|
||||||
DEBUG("history.find", "Removing price: " << symbol() << " on " << date);
|
DEBUG("history.find", "Removing price: " << symbol() << " on " << date);
|
||||||
|
|
||||||
|
|
@ -83,7 +83,7 @@ void commodity_t::map_prices(function<void(datetime_t, const amount_t&)> fn,
|
||||||
else
|
else
|
||||||
when = CURRENT_TIME();
|
when = CURRENT_TIME();
|
||||||
|
|
||||||
pool().commodity_price_history.map_prices(fn, *this, when, _oldest,
|
pool().commodity_price_history.map_prices(fn, referent(), when, _oldest,
|
||||||
bidirectionally);
|
bidirectionally);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -159,9 +159,9 @@ commodity_t::find_price(const commodity_t * commodity,
|
||||||
|
|
||||||
optional<price_point_t>
|
optional<price_point_t>
|
||||||
point(target ?
|
point(target ?
|
||||||
pool().commodity_price_history.find_price(*this, *target,
|
pool().commodity_price_history.find_price(referent(), *target,
|
||||||
when, oldest) :
|
when, oldest) :
|
||||||
pool().commodity_price_history.find_price(*this, when, oldest));
|
pool().commodity_price_history.find_price(referent(), when, oldest));
|
||||||
|
|
||||||
// Record this price point in the memoization map
|
// Record this price point in the memoization map
|
||||||
if (base->price_map.size() > base_t::max_price_map_size) {
|
if (base->price_map.size() > base_t::max_price_map_size) {
|
||||||
|
|
@ -206,7 +206,7 @@ commodity_t::check_for_updated_price(const optional<price_point_t>& point,
|
||||||
DEBUG("commodity.download",
|
DEBUG("commodity.download",
|
||||||
"attempting to download a more current quote...");
|
"attempting to download a more current quote...");
|
||||||
if (optional<price_point_t> quote =
|
if (optional<price_point_t> quote =
|
||||||
pool().get_commodity_quote(*this, in_terms_of)) {
|
pool().get_commodity_quote(referent(), in_terms_of)) {
|
||||||
if (! in_terms_of ||
|
if (! in_terms_of ||
|
||||||
(quote->price.has_commodity() &&
|
(quote->price.has_commodity() &&
|
||||||
quote->price.commodity_ptr() == in_terms_of))
|
quote->price.commodity_ptr() == in_terms_of))
|
||||||
|
|
@ -220,12 +220,11 @@ commodity_t::check_for_updated_price(const optional<price_point_t>& point,
|
||||||
commodity_t& commodity_t::nail_down(const expr_t& expr)
|
commodity_t& commodity_t::nail_down(const expr_t& expr)
|
||||||
{
|
{
|
||||||
annotation_t new_details;
|
annotation_t new_details;
|
||||||
|
|
||||||
new_details.value_expr = expr;
|
new_details.value_expr = expr;
|
||||||
new_details.add_flags(ANNOTATION_VALUE_EXPR_CALCULATED);
|
new_details.add_flags(ANNOTATION_VALUE_EXPR_CALCULATED);
|
||||||
|
|
||||||
commodity_t * new_comm =
|
return *pool().find_or_create(symbol(), new_details);
|
||||||
commodity_pool_t::current_pool->find_or_create(symbol(), new_details);
|
|
||||||
return *new_comm;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
commodity_t::operator bool() const
|
commodity_t::operator bool() const
|
||||||
|
|
|
||||||
|
|
@ -188,6 +188,9 @@ public:
|
||||||
return comm == *this;
|
return comm == *this;
|
||||||
return base.get() == comm.base.get();
|
return base.get() == comm.base.get();
|
||||||
}
|
}
|
||||||
|
bool operator==(const string& name) const {
|
||||||
|
return base_symbol() == name;
|
||||||
|
}
|
||||||
|
|
||||||
static bool symbol_needs_quotes(const string& symbol);
|
static bool symbol_needs_quotes(const string& symbol);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,24 +20,24 @@ While parsing file "src/amount.h", line 121:
|
||||||
Error: Unexpected whitespace at beginning of line
|
Error: Unexpected whitespace at beginning of line
|
||||||
While parsing file "src/amount.h", line 132:
|
While parsing file "src/amount.h", line 132:
|
||||||
Error: Unexpected whitespace at beginning of line
|
Error: Unexpected whitespace at beginning of line
|
||||||
While parsing file "src/amount.h", line 693:
|
While parsing file "src/amount.h", line 702:
|
||||||
Error: Unexpected whitespace at beginning of line
|
Error: Unexpected whitespace at beginning of line
|
||||||
While parsing file "src/amount.h", line 723:
|
While parsing file "src/amount.h", line 732:
|
||||||
Error: Unexpected whitespace at beginning of line
|
Error: Unexpected whitespace at beginning of line
|
||||||
While parsing file "src/amount.h", line 731:
|
|
||||||
Error: Unexpected whitespace at beginning of line
|
|
||||||
While parsing file "src/amount.h", line 734:
|
|
||||||
Error: Invalid date/time: line amount_t amoun
|
|
||||||
While parsing file "src/amount.h", line 740:
|
While parsing file "src/amount.h", line 740:
|
||||||
|
Error: Unexpected whitespace at beginning of line
|
||||||
|
While parsing file "src/amount.h", line 743:
|
||||||
|
Error: Invalid date/time: line amount_t amoun
|
||||||
|
While parsing file "src/amount.h", line 749:
|
||||||
Error: Invalid date/time: line string amount_
|
Error: Invalid date/time: line string amount_
|
||||||
While parsing file "src/amount.h", line 746:
|
While parsing file "src/amount.h", line 755:
|
||||||
Error: Invalid date/time: line string amount_
|
Error: Invalid date/time: line string amount_
|
||||||
While parsing file "src/amount.h", line 752:
|
While parsing file "src/amount.h", line 761:
|
||||||
Error: Invalid date/time: line string amount_
|
Error: Invalid date/time: line string amount_
|
||||||
While parsing file "src/amount.h", line 758:
|
While parsing file "src/amount.h", line 767:
|
||||||
Error: Invalid date/time: line std::ostream&
|
Error: Invalid date/time: line std::ostream&
|
||||||
While parsing file "src/amount.h", line 765:
|
While parsing file "src/amount.h", line 774:
|
||||||
Error: Invalid date/time: line std::istream&
|
Error: Invalid date/time: line std::istream&
|
||||||
While parsing file "src/amount.h", line 771:
|
While parsing file "src/amount.h", line 780:
|
||||||
Error: Unexpected whitespace at beginning of line
|
Error: Unexpected whitespace at beginning of line
|
||||||
end test
|
end test
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue